package com.shrcl.engineerprocess.domain.impl;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.Certification;
import com.shrcl.engineerprocess.domain.CertificationAgencyCode;
import com.shrcl.engineerprocess.domain.impl.CertificationAgencyCodeImpl;
import com.shrcl.engineerprocess.domain.proxy.CertificationProxy;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("CERTIFICATION_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "certification")
public class CertificationImpl extends BaseModelObject implements Certification {
  public CertificationImpl() {
    super();
  }
  
  @JoinColumn(name = "agency_id")
  @ManyToOne(targetEntity = CertificationAgencyCodeImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private CertificationAgencyCode agency;
  
  public CertificationAgencyCode getAgency() {
    return this.agency;
  }
  
  public Certification setAgency(final CertificationAgencyCode agency) {
    this.agency = agency;
    return this;			
    
  }
  
  private String name;
  
  public String getName() {
    return this.name;
  }
  
  public Certification setName(final String name) {
    this.name = name;
    return this;			
    
  }
  
  private String level;
  
  public String getLevel() {
    return this.level;
  }
  
  public Certification setLevel(final String level) {
    this.level = level;
    return this;			
    
  }
  
  private Integer validity;
  
  public Integer getValidity() {
    return this.validity;
  }
  
  public Certification setValidity(final Integer validity) {
    this.validity = validity;
    return this;			
    
  }
  
  private Integer reExamineCycle;
  
  public Integer getReExamineCycle() {
    return this.reExamineCycle;
  }
  
  public Certification setReExamineCycle(final Integer reExamineCycle) {
    this.reExamineCycle = reExamineCycle;
    return this;			
    
  }
  
  public String getEntityName() {
    return this.name;
  }
  
  public void checkValid() {
    boolean _notEquals = (!Objects.equal(this.validity, null));
    Validates.Assert(_notEquals, "\u6709\u6548\u671F\u4E0D\u80FD\u4E3A\u7A7A");
    boolean _notEquals_1 = (!Objects.equal(this.name, null));
    Validates.Assert(_notEquals_1, "\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");
  }
  
  public static Certification create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.Certification certification = new com.shrcl.engineerprocess.domain.impl.CertificationImpl(
    );
    objectFactory.create(certification);
    return certification;			
    
  }
  
  public static Certification createCertificationImpl(final IObjectFactory objectFactory, final Procedure1<Certification> init) {
    com.shrcl.engineerprocess.domain.Certification certification = new com.shrcl.engineerprocess.domain.impl.CertificationImpl(
    );
    objectFactory.create(certification);
    init.apply(certification);
    
    return certification;			
    
  }
  
  public CertificationProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.CertificationProxy proxy = new com.shrcl.engineerprocess.domain.proxy.CertificationProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
